package core.time;


//some units that translate?
public class GameTime implements Comparable<GameTime>{

	public static final long MS_PER_GAMETIME = 100;
	
	public static GameTime fromSeconds(double d){
		return fromMilliseconds((long) (d * 1000));
	}
	
	public static GameTime fromMilliseconds(long l){
		return new GameTime((int)(l/MS_PER_GAMETIME));
	}
	
	private long startTime, endTime;
	private int duration;
	
	/**
	 * i = the number of GameTime units.
	 * @param i
	 */
	public GameTime(int i){
		startTime = System.currentTimeMillis();
		endTime = startTime + i * MS_PER_GAMETIME;
		
	}

/**
 * beware this cast. Shouldn't matter.
 */
	public int compareTo(GameTime o) {
		return (int)(getEndTime() - o.getEndTime());
	}
	
	public GameTime subtract(GameTime gt){
		return GameTime.fromMilliseconds(this.getEndTime() - gt.getEndTime());
	}
	
	public long getEndTime(){
		return endTime;
	}
	
	public int getDuration(){
		return duration;
	}
	/**
	 * returns the difference between the stored time and now. all GameTimes are relative.
	 * @return
	 */
	public long toMilliseconds(){
		return duration * MS_PER_GAMETIME;
	}
}
